package com.zm.zb100.repository;

import com.zm.zb100.persistence.entity.db.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * UserRepository
 *
 * <p>
 * </p>
 *
 * @author chuanbai
 * @date 2024/4/2
 */
@Repository
public interface UserRepository extends JpaRepository<User, Long> {

    @Modifying
    @Query("delete from User u where u.id in :idList")
    Boolean deleteByIdIn(@Param("idList") List<Long> idList);

    @Query(value = "select u.* from user u left join class on u.id = class.id " +
            "order by u.id",
            countQuery = "SELECT COUNT(*) " +
                    "FROM ( " +
                    " select u.* from user u left join class on u.id = class.id order by u.id asc " +
                    " ) AS a",
            nativeQuery = true)
    Page<User> findTest(Pageable pageable);
}
